<script setup lang="ts">
import { ref } from 'vue';
const searchValue = ref('');

const scan = () => {
  uni.scanCode({
    success: (res) => {
      // 跳转溯源详情页
      uni.navigateTo({
        url: `/pages/traceabilityDetails/traceabilityDetails`
      });
    }
  });
};
const search = () => {
  uni.navigateTo({
    url: `/pages/traceabilityDetails/traceabilityDetails?code=${searchValue.value}`
  });
};
</script>
<template>
  <view class="box">
    <view class="title">
      <text>预制菜溯源平台</text>
    </view>
    <view class="subtitle">
      <text>安全! 安心！ 溯源！</text>
    </view>
    <view>
      <u-search placeholder="输入溯源码" :show-action="false" v-model="searchValue" @search="search"></u-search>
    </view>

    <view class="or">
      <text>或者</text>
    </view>
    
    <view class="scan" @tap="scan">
      <image src="/src/static/icons/scan.png" class="scan-icon"></image>
      <view class="scan-text">
        <text>点击扫码溯源</text>
      </view>
    </view>
  </view>
</template>
<style scoped>
.box {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  text-align: center;
  background: linear-gradient(to bottom, #ffffff, #f8f8f8);
  padding: 0 30rpx;
}

.title {
  margin-top: 15vh;
  font-size: 48rpx;
  font-weight: 600;
  margin-bottom: 20rpx;
  color: #333;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  letter-spacing: 2rpx;
}

.subtitle {
  font-family: 'Courier New', Courier, monospace;
  font-weight: 500;
  margin-bottom: 40rpx;
  color: #666;
  font-size: 28rpx;
  letter-spacing: 4rpx;
}

/* 搜索框容器 */
.box > view:nth-child(3) {
  width: 90%;
  margin: 0 auto;
  padding: 20rpx;
  background-color: #fff;
  border-radius: 16rpx;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.or {
  margin-top: 40rpx;
  font-size: 28rpx;
  font-weight: 400;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.or text {
  position: relative;
  padding: 0 30rpx;
}

.or text::before,
.or text::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 60rpx;
  height: 1px;
  background-color: #e0e0e0;
}

.or text::before {
  left: -60rpx;
}

.or text::after {
  right: -60rpx;
}

.scan {
  margin-top: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30rpx;
  background-color: #fff;
  border-radius: 16rpx;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  width: 90%;
  margin-left: auto;
  margin-right: auto;
  transition: all 0.3s ease;
}

.scan:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.scan-icon {
  width: 80rpx;
  height: 80rpx;
  margin-right: 20rpx;
}

.scan-text {
  font-size: 32rpx;
  font-weight: 500;
  color: #63aa5d;
}


</style>